package com.yyb.utils.core;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5加密工具类
 *
 * @Author : Marshal
 * @Create : 2018/2/10 13:15
 */
public class MD5Util {

    public static String getMd5(String inStr){
        String outStr = null;
        if (inStr == null || "".equals(inStr)){
            outStr = inStr;
        }else{
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(inStr.getBytes());
                byte b[] = md.digest();
                StringBuffer buf = new StringBuffer();
                for(int i = 1; i<b.length; i++) {
                    int c = b[i]>>>4 & 0xf;
                    buf.append(Integer.toHexString(c));
                    c = b[i]& 0xf;
                    buf.append(Integer.toHexString(c));
                }
                outStr = buf.toString();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        }
        return outStr;
    }

}
